using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;
//using NUnit.Framework.SyntaxHelpers;

using Rhino.Mocks;

using Liberty.Application.GrantManagement;
using Liberty.Domain.GrantManagement;
using Liberty.Domain.CaseManagement;
using Liberty.Persistence.GrantManagement;

using Peradigm.Framework.Domain.Security;

namespace Tests.ApplicationTests.GrantManagement
{
#if DEBUG
    [TestClass()]
    public class GrantControllerTests : Object
    {
        #region Constants
        #endregion

        #region SetUp and TearDown GrantControllerTests
        [TestInitialize()]
        public void SetUpGrantControllerTests()
        {
        }

        [TestCleanup()]
        public void TearDownGrantControllerTests()
        {
        }
        #endregion

        #region Test Methods
        [TestMethod()]
        public void TestGrantsFor()
        {
            // Create a "mock repository."  This will keep track of all of the mocking to be recorded and verified.
            MockRepository mocks = new MockRepository();           
            
            // Create a list of fake grants that we want to have our mock broker return, so that we can test our controller
            // in isolation.  Testing of the actuall broker will of course be done in its own test fixture.
            List<Grant> grants = new List<Grant>();
            grants.Add( new Grant() );

            // Create a mock grant broker.  This object will mock the real grant broker and return what we tell it to
            // return, namely a list of grants when sent the message GrantsFor( criteria ).
            GrantBroker mockedBroker = mocks.DynamicMock<GrantBroker>( String.Empty );
            
            // Give our GrantController, the unit we are actually testing here, the mocking grant broker.
            GrantController grantController = new GrantController();
            grantController.GrantBroker = mockedBroker;

            // Tell the mock repository to expect that the message GrantsFor(..) will be sent to the mocked grant broker,
            // to ignore the arguments sent to the mocked broker, and to always return our fake grants list when
            // this message is sent.
            Expect.On( mockedBroker ).Call( mockedBroker.GrantsMatching( new GrantSearchCriteria( 1L ) ) ).IgnoreArguments().Return( grants );

            // Tell the mock repository to get ready to replay what was "recorded" above when the mocks are accessed.
            // Initializes mocked object.
            mocks.ReplayAll();

            // Create a User and verify that the grants returned from the GrantController 
            // for that user are what is returned from our mock broker.
            CaseVolunteer aVolunteer = CaseVolunteer.TestInstance();            

            Assert.AreEqual( grants, grantController.GrantsFor( aVolunteer ) );

            // Tell the mock repository to verify that all object interactions
            // happened as recorded/expected.  If they do not, the unit test will fail.
            mocks.VerifyAll();
        }	

        #endregion

        #region Support Methods
        #endregion

        #region Data Elements
        #endregion

    }
#endif
	
}
